# -*- coding: utf-8 -*-

 ###############################################
 ##                                             ##
 ##   Punto de Venta                             ##
 ##                                              ##
 ##   for Basiq Empresa                          ##
 ##                                              ##
 ##   by Críptidos Digitales                     ##
 ##   GPL (c)2008                                ##
  ##                                             ##
    ###############################################


from PyQt4 import QtCore, QtGui

import puntoVenta_ui

from cdWidgets import cdSlideFrame

import ventas



class Forma(QtGui.QFrame):

    def __init__(self, *args, **kwds):
        if kwds.has_key('app'):
            self.__app = kwds.pop('app')
        else:
            self.__app = None

        if kwds.has_key('content'):
            self.__content = kwds.pop('content')
        else:
            self.__content = None

        if 'eventRouter' in kwds.keys():
            self.__eventRouter = kwds.pop('eventRouter')
        else:
            self.__eventRouter = None

        if kwds.has_key('owner'):
            self.__owner = kwds.pop('owner')
        else:
            self.__owner = None

        QtGui.QFrame.__init__(self, *args)

        self.ui = puntoVenta_ui.Ui_Form()
        self.ui.setupUi(self)

        self.ui.tabWidget.clear()

        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(9*self.app.fontZoom)

        self.ui.tabWidget.clear()
        self.ui.tabWidget.setFont(font)

        ## Ventas
        self.app.setController('ventas', ventas.Controller(app=self.app, eventRouter= self.eventRouter))

        self.ui.ventas = self.app.controller('ventas').Form(self, modo='captura')

        self.ui.tabWidget.addTab(self.ui.ventas, u"&VENTA")

        if self.ui.tabWidget.count() == 1:
            self.ui.tabWidget.tabBar().hide()

        self.connect(self.owner, QtCore.SIGNAL('capturaPagoObligatoriaChanged'), self.capturaPagoObligatoriaChanged)
        self.connect(self.owner, QtCore.SIGNAL('clasificacionesChangedBroadcast()'), self.clasificacionesChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('clientesChangedBroadcast()'), self.clientesChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('empleadosChangedBroadcast()'), self.empleadosChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('lugaresChangedBroadcast()'), self.lugaresChangedBroadcast)
        self.connect(self.owner, QtCore.SIGNAL('rangosPrecioChangedBroadcast()'), self.rangosPrecioChangedBroadcast)


    def addProduct(self):
        self.owner.emit(QtCore.SIGNAL('addProduct()'))

    @property
    def app(self):
        return self.__app

    def capturaPagoObligatoriaChanged(self):
        self.emit(QtCore.SIGNAL('capturaPagoObligatoriaChanged'))

    def clasificacionesChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('clasificacionesChangedBroadcast()'))

    def clientesChanged(self):
        self.emit(QtCore.SIGNAL("clientesChanged()"))

    def clientesChangedBroadcast(self):
        m = "puntoVenta.Forma.clientesChangedBroadcast()"

        self.emit(QtCore.SIGNAL("clientesChangedBroadcast()"))

    def empleadosChangedBroadcast(self):
        m = "puntoVenta.Forma.empleadosChangedBroadcast()"
        self.emit(QtCore.SIGNAL("empleadosChangedBroadcast()"))

    @property
    def eventRouter(self):
        return self.__eventRouter

    def lugaresChanged(self):
        self.emit(QtCore.SIGNAL('lugaresChanged()'))

    def lugaresChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('lugaresChangedBroadcast()'))

    @property
    def owner(self):
        return self.__owner

    def rangosPrecioChangedBroadcast(self):
        self.emit(QtCore.SIGNAL('rangosPrecioChangedBroadcast()'))

    def ventasChanged(self):
        self.emit(QtCore.SIGNAL('ventasChanged()'))


